package com.garrett.demo.sys.dao;

import com.garrett.demo.sys.entity.Account;
import com.garrett.demo.sys.entity.SimsStudent;

public class UserDataBaseDemo implements UserDao {

    private static SimsStudent[] students = new SimsStudent[100];

    private static Account[] accounts = new Account[100];

    static {
        accounts[0] = new Account("1", "211805142", "admin");
        students[0] = new SimsStudent("211805142", "张佳伟", "350626********3516", "181****1096", "1", "1273993501@qq.com", "admin");

    }
   public static void fz(){
       UserDaoTextImp s = new UserDaoTextImp();
       for (int i = 1; i < 1 + s.count(); i++) {
           students[i]= s.getStudent()[i - 1];
           accounts[i]=s.getAccount()[i-1];
       }
   }

    public SimsStudent[] getStudents() {
        return students;
    }

    public Account[] getAccounts() {
        return accounts;
    }

    @Override
    public SimsStudent getStudentById(String id) {
        for (int i = 0; i < accounts.length; i++) {
            if(accounts[i] != null) {
                if (accounts[i].getId().equals(id) ) {
                    return new SimsStudent(students[i].getStudentId(), students[i].getStudentName(), students[i].getIdCardNo(), students[i].getMobilePhone(), students[i].getGender(), students[i].getEmail(), students[i].getPassword());
                }
            }else{
                    break;
                }
        }
        return null;
    }

    @Override
    public Account getUserByAccount(String account) {
        for (int i = 0; i < accounts.length; i++) {
            if(accounts[i] != null) {
                if (accounts[i].getAccount().equals(account)) {
                    return this.getAccounts()[i];
                }
            }
        }
        return null;
    }

    @Override
    public int addAccount(Account account) {
        for (int i = 0; i < accounts.length; i++) {
            if(accounts[i] == null){
                accounts[i] = account;
                return 1;
            }else if(accounts[i].getAccount().equals(account.getAccount())){
                return 0;
            }
        }
        return 0;
    }

    @Override
    public int delAccountById(String id) {
        return 0;
    }

    @Override
    public int modifyAccount(Account account) {
        return 0;
    }

    @Override
    public int createUser(SimsStudent userInfo) {
        for (int i = 0; i < students.length; i++) {
            if(students[i] == null){
                students[i] = userInfo;
                return 1;
            }else if(students[i].getStudentId().equals(userInfo.getStudentId())){
                return 0;
            }
        }
        return 0;
    }

    @Override
    public int delStudentInfo(String stuId) {
        return 0;
    }

    @Override
    public int modifyStudentInfo(SimsStudent student) {
        return 0;
    }

    @Override
    public SimsStudent[] getAllStudent() {
        return new SimsStudent[0];
    }
}
